<div class='panel modal-dialog modal-md ' style="top: 50px;"  aria-hidden="true">
    <div class='panel-heading bg-silver'>
        <div class='panel-heading-btn'>
            <button class='btn btn-xs btn-icon btn-circle btn-danger' onclick="$('#selectSetUser').modal('hide');" ><i class='fa fa-times'></i></button>
        </div>
        <h3 class='panel-title'><span class="color-black">选择员工</span></h3>
    </div>
    <div class="panel-body  height-400 overflow-auto">
        <div class="row p-lg-2 m-5">
            <div class="row col-md-6 pull-left">
                <h5 class="m-b-5">请选择要分配的同事:</h5>
                <div class="border-solid-1 height-300 overflow-auto">
                    <div class="panel panel-inverse" data-sortable-id="tree-view-2">
                        <div class="panel-body">
                            <div id="usingSet_json"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row col-md-5 pull-right">
                <h5 class="m-b-5">已选择的同事:<small>请从左侧选择后添加</small></h5>
                <div class="border-solid-1 height-300 p-3 " id="user_Set_selectfor"></div>
            </div>
        </div>
    </div>
    <div class="panel-footer">
        <button class="btn btn-sm btn-success pull-right m-3" onclick="selectSetUsers()">选择</button>
        <button class="btn btn-sm btn-white pull-right m-3" onclick="$('#selectSetUser').modal('hide');">取消</button>
        <div class="clearfix"></div>
    </div>
</div>

<script>
    $(function() {
         $.post(ctx+"dept/getUseeAndDepttree",{},function (r) {
                var array  = r.msg;
                $("#usingSet_json").jstree({
                    "core": {
                        "multiple": false,//单选
                        "data":array
                    },
                    "checkbox" : {
                        "keep_selected_style" : false
                    },
                    "plugins" : [ "wholerow", "checkbox" ]
                });
                // 获得点击节点的id
                $('#usingSet_json').on("changed.jstree", function (e, data) {
                    var nodeid = data.node.id;
                    var text = data.node.text;
                    var action = data.action;;
                    if (action == "deselect_node") {
                        $("#user_Set_selectfor").find("div").each(function () {
                            var data_id = $(this).attr("data-id");
                            if (data_id == nodeid) $(this).remove();
                        });
                    }else{
                        var label = "<div class='label label-danger p-3 m-3 pull-left' data-id='"+nodeid+"'>"+text+"</div>";
                        $("#user_Set_selectfor").empty().append(label);
                    }
                });
            });

    });

</script>
